import * as vscode from 'vscode';
import { Pet } from './modules/Pet';
import { ActivityMonitor } from './modules/activityMonitor';

/**
 * 插件激活函数
 * @param context 插件上下文
 */
export function activate(context: vscode.ExtensionContext) {
    console.log('Congratulations, your extension "code-pal" is now active!');

    // 启动时显示随机古诗词
    const welcomePoems = [
        '人生若只如初见，何事秋风悲画扇！',
        '此情可待成追忆，只是当时已惘然！',
        '曾经沧海难为水，除却巫山不是云！',
        '衣带渐宽终不悔，为伊消得人憔悴！'
    ];
    const randomPoem = welcomePoems[Math.floor(Math.random() * welcomePoems.length)];
    vscode.window.showInformationMessage(randomPoem);

    // 初始化程序员伙伴
    const pet = new Pet(context);
    
    // 初始化活动监听
    const activityMonitor = new ActivityMonitor(pet);
    activityMonitor.start();

    // 注册命令
    const disposable = vscode.commands.registerCommand('code-pal.helloWorld', () => {
        vscode.window.showInformationMessage('Hello World from Code Pal!');
    });

    const petInteract = vscode.commands.registerCommand('code-pal.petInteract', () => {
        pet.showPetSelection();
    });

    // 注册清理回调
    context.subscriptions.push(
        disposable,
        petInteract,
        pet,
        {
            dispose: () => activityMonitor.stop()
        }
    );
}

/**
 * 插件停用函数
 */
export function deactivate() {}
